﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace blackhouse.WebNemo.Business.Groups {
    public class GroupColumnCollection : IEnumerable<GroupColumn> {

        #region Fields

        private readonly Dictionary<string, GroupColumn> namedColumns = new Dictionary<string, GroupColumn>();
        private readonly Dictionary<int, GroupColumn> signedColumns = new Dictionary<int, GroupColumn>();
        private readonly List<GroupColumn> columns = new List<GroupColumn>(); 

        #endregion

        #region Constructors

        #endregion

        #region Properties

        public GroupColumn this[string name] {
            get {
                if (this.namedColumns.ContainsKey(name))
                    return this.namedColumns[name];
                else
                    return null;
            }
        }

        public GroupColumn this[int columnId] {
            get {
                if (this.signedColumns.ContainsKey(columnId))
                    return this.signedColumns[columnId];
                else
                    return null;
            }
        }

        public int Count {
            get { return this.columns.Count; }
        }

        #endregion

        #region Methods

        public void Clear() {
            this.namedColumns.Clear();
            this.signedColumns.Clear();
            this.columns.Clear();
        }

        public void Add(GroupColumn column) {
            if (column != null && !this.namedColumns.ContainsKey(column.ColumnName)) {
                this.namedColumns.Add(column.ColumnName, column);
                this.signedColumns.Add(column.ColumnId, column);
                this.columns.Add(column);
            }
        }

        public IEnumerator<GroupColumn> GetEnumerator() {
            return this.columns.GetEnumerator();
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() {
            return this.columns.GetEnumerator();
        }

        #endregion

    }
}
